package org.bulu.project.web.controller.admin;

import com.github.pagehelper.PageInfo;
import org.bulu.project.person.service.VideoCheckService;
import org.bulu.project.common.result.PageResult;
import org.bulu.project.common.result.Result;
import org.bulu.project.system.model.bo.VideoCheckBO;
import org.bulu.project.system.model.query.VideoPageQuery;
import org.bulu.project.system.model.vo.VideoCheckVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController()
@RequestMapping("admin")
public class VideoCheckController {

    @Autowired
    private VideoCheckService videoCheckService;

    /**
     * 根据查询条件获取视频分页列表
     * @param queryParams 查询条件
     * @return 分页列表
     */
    @PostMapping("/page")
    public PageResult<VideoCheckVO> listPagedVideo(
            VideoPageQuery queryParams
    ) {
        PageInfo page = videoCheckService.listPageVideos(queryParams);
        return PageResult.success(page);
    }

    /**
     * 查看视频详情页面
     * @param vid 视频ID
     * @return 视频详情页面
     */
    @PostMapping("/check")
    public Result checkVideo(
            @RequestParam("vid") Integer vid
    ) {
        VideoCheckBO videoCheckBO = videoCheckService.getVideoDetail(vid);

        return Result.success(videoCheckBO);
    }

    /**
     * 进行审核，修改视频的审核状态
     */
    @PostMapping("/audit")
    public Result auditVideo(
            @RequestParam("vid") Integer vid,
            @RequestParam("status") Integer status
    ) {
        int result = videoCheckService.checkVideo(vid, status);
        if (result == 1) {
            videoCheckService.notifyUser(vid, status);
            return Result.success();
        } else {
            return Result.failed("审核失败");
        }
    }

    /**
     * 批量删除视频
     */
    @PostMapping("/delete")
    public Result deleteBatchVideo(
            @RequestParam("vids") Integer[] vids
    ) {
        int result = videoCheckService.deleteBatchVideo(vids);
        if (result == vids.length) {
            return Result.success();
        } else {
            return Result.failed("删除失败");
        }
    }

}
